package com.qyhl.webtv.module_news.utils.view;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.widget.TextView;

import com.qyhl.cloud.webtv.module_news.R;
import com.qyhl.webtv.commonlib.utils.cache.SpfManager;

import razerdp.basepopup.BasePopupWindow;

/**
 * Created by qyhl on 2018/4/18.
 * 新闻详情弹出框
 */

public class DetailNewsMorePopup extends BasePopupWindow {
    private View popupView;

    private FontSizeSeekBarView fontSizeSeekBar;

    private TextView cancelBtn;

    private TextView shareBtn;

    private MorePopupListener popupListener;

    public void setPopupListener(MorePopupListener popupListener) {
        this.popupListener = popupListener;
    }

    public DetailNewsMorePopup(Activity context, int position) {
        super(context);
        bindEvent(context, position);
    }

    @Override
    protected Animation initShowAnimation() {
        return getDefaultScaleAnimation();
    }



    @Override
    public View getClickToDismissView() {
        return getPopupWindowView();
    }

    @Override
    public View onCreatePopupView() {
        popupView = LayoutInflater.from(getContext()).inflate(R.layout.news_popup_news_detail_more, null);
        return popupView;
    }

    @Override
    public View initAnimaView() {
        return findViewById(R.id.popup_anima);
    }

    private void bindEvent(final Activity context, int position) {
        fontSizeSeekBar = (FontSizeSeekBarView) popupView.findViewById(R.id.fontsize_seekbar);

        cancelBtn = (TextView) popupView.findViewById(R.id.popup_cancel);

        shareBtn = (TextView) popupView.findViewById(R.id.popup_share);

        fontSizeSeekBar.setSmallNum(5);
        fontSizeSeekBar.setPosition(position);

        fontSizeSeekBar.setFontSizeSeekBarChangeListener(pos -> {
            SpfManager.getInstance(context).putInt("fontSize", pos);
            popupListener.doSeekbar(pos);
        });

        shareBtn.setOnClickListener(v -> popupListener.doShare());

        cancelBtn.setOnClickListener(v -> dismiss());


    }

    public interface MorePopupListener {
        /**
         * 分享
         */
        void doShare();

        /**
         * 字体条的拖动改变
         *
         * @param position
         */
        void doSeekbar(int position);
    }
}
